package cn.edu.jlu.community.app.profile;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.UpdatePasswordCallback;
import com.avos.avoscloud.feedback.FeedbackAgent;

import cn.edu.jlu.community.R;

public class UserProfile extends Activity {

    private void changePasswd(String older_password , String new_password) {
        AVUser.getCurrentUser().updatePasswordInBackground(older_password, new_password, new UpdatePasswordCallback() {
            @Override
            public void done(AVException e) {
                if (e == null) {
                    Log.i("aaa", "change pass test completed");
                    Toast.makeText(UserProfile.this, "password changed .", Toast.LENGTH_LONG).show();
                } else {
                    Log.i("aaa", e.getMessage());
                    Toast.makeText(UserProfile.this, e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });
    }
    private String getUserinfo(){
        StringBuilder sb = new StringBuilder() ;
        sb.append(AVUser.getCurrentUser().getUsername()+"\n")
                .append(AVUser.getCurrentUser().getMobilePhoneNumber())
                .append("\n and so on") ;
        return sb.toString() ;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_profile);

        // simple textview and button just for testing .
        TextView tv = (TextView)findViewById(R.id.userInfoTv);
        tv.setText(getUserinfo()) ;

        findViewById(R.id.changepassbtn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                changePasswd("older_password" , "String new_password") ;
            }
        });

        findViewById(R.id.feedbackbtn).setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                FeedbackAgent agent = new FeedbackAgent(getApplicationContext());
                agent.startDefaultThreadActivity();
            }
        });
    }
}
